const express=require('express');
// 创建路由对象
const router=express.Router();
// 配置路由规则

router.get('/',(req,res)=>{
    res.send(`<h1>api server running</h1>`);
})

// get请求
router.get('/get',(req,res)=>{
    res.send({
        status:200,
        msg:'ok'
    });
});

router.get('/get/:id',(req,res)=>{
    res.json({
        status:200,
        msg:'success',
        data:{
            params:req.params,
            query:req.query
        }
    });
});

// post请求
router.post('/post',(req,res)=>{
    res.send({
        status:200,
        msg:'ok'
    });
});
router.post('/post/:id',(req,res)=>{
    res.json({
        status:200,
        msg:'success',
        data:{
            params:req.params,
            body:req.body,
            query:req.query
        }
    });
});

// put请求
router.put('/put',(req,res)=>{
    res.json({
        status:200,
        msg:'ok'
    });
});

router.put('/put/:id',(req,res)=>{
    res.json({
        status:200,
        msg:'ok',
        data:{
            params:req.params,
            body:req.body,
            query:req.query
        }
    });
});

// delete请求
router.delete('/delete/:id',(req,res)=>{
    res.send({
        status:200,
        msg:'success',
        data:{
            params:req.params,
            body:req.body,
            query:req.query
        }
    });
});

// patch请求
router.patch('/patch',(req,res)=>{
    res.json({
        status:200,
        msg:'ok'
    });
});
router.patch('/patch/:id',(req,res)=>{
    res.json({
        status:200,
        msg:'success',
        data:{
            params:req.params,
            body:req.body,
            query:req.query
        }
    });
});

// 导出路由对象
module.exports=router;